"""
This module defines the WSGI entry point for this application.
"""

def make_app(global_conf, **app_conf):
    store_module = app_conf.get('store_module', 'core')
    app = app_conf.get('application', 'core')
    renderer = app_conf.get('renderer', 'core')
    repository_cname = app_conf.get('repository_type', 'flatfile') + '_repository'
    bcstore = __import__('brightcontent.%s.store' % store_module,
                         globals, locals, [repository_cname])
                         #fromlist=[repository_cname]) #Can use this form only on Python 2.5
    repository_class = getattr(bcstore, repository_cname)
    #store = getattr(getattr(brightcontent, store_module), 'store')
    store = repository_class(**app_conf)

    brightcontent = __import__('brightcontent.%s.application' % app)
    bccore = getattr(getattr(brightcontent, app), 'application')

    brightcontent = __import__('brightcontent.%s.renderer' % renderer)
    renderer = getattr(getattr(brightcontent, renderer), 'renderer')

    bccore = renderer.FeedRenderer(bccore.WsgiApplication(None, store, app_conf), app_conf)

    plugins = app_conf.get('plugins')
    plugininfo = locals().copy()
    if plugins:
        execfile(plugins, globals(), plugininfo)
        app = plugininfo['app']
    else:
        raise ValueError('User did not specify plugins config')

    #app should have been defined in plugins.py
    return app

